<%@ page language="java" isELIgnored="false" import="java.util.*"
	pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ page import="com.kit.authority.entity.User"%>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%@include file="/common/include.jsp"%>
<link href="<%=request.getContextPath() %>/fare/js/datePicker/skin/WdatePicker.css" rel="stylesheet" type="text/css">
<link href='<%=request.getContextPath()%>/fare/js/cityquery/cityquery.css' rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<%=request.getContextPath() %>/fare/js/datePicker/WdatePicker.js"></script>
<script type='text/javascript' src='<%=request.getContextPath()%>/fare/js/cityquery/citylist.js'></script>
<script type='text/javascript' src='<%=request.getContextPath()%>/fare/js/cityquery/querycity4.js'></script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>用户意见反馈</title>
<script>
		$(function(){
			$('#departure').querycity({'data':citysFlight,'tabs':labelFromcity,'hotList':hotList});
			$('#destination').querycity({'data':citysFlight,'tabs':labelFromcity,'hotList':hotList});
			$('#opinionList').datagrid({
				//title: '列表',
				pagination:true,
				nowrap: false,
                striped: true,
                collapsible: true,
				toolbar:[{
					text:'添加',
					iconCls:'icon-add',
					handler:function(){
						$("#opinionWindows").css("height","310px");
						WinOpen();
					}
				},'-',{
					text:'删除',
					iconCls:'icon-remove',
					handler:function(){
						remove();
					}
				},'-',{
					text:'更新',
					iconCls:'icon-edit',
					handler:function(){
					    update();
					}
				},'-',{
					text:'查询',
					iconCls:'icon-search',
					handler:function(){
					    $('#opinionList').datagrid('options').url = 'priceAction!getPriceListJSON.action';
					    $('#opinionList').datagrid("reload");
					}
				}],
				 rownumbers:false,
				 frozenColumns:[[
				    {field:'ck',checkbox:true},
				    {title:'序号',field:'rownum',width:"35"}
				]],
				onLoadSuccess: function () {
				    $('.datagrid-toolbar').append($('#searchTable'));
				    $('#searchTable').show(); 		    
				}
			});
		});
		
		function WinOpen(row){
			   if(row!=null){
				   var $secondTr = $("#tableInsertUpdate tr:eq(1)");
				   if($secondTr.attr("id")!='idtr'){
					   var $idShow = $("<tr class='tab' id='idtr'><td style='width: 22%; text-align: left;' class='td1'>ID:</td> <td><input class='easyui-validatebox' required='required' type='text' id='id' name='id' readonly='readonly'></td></tr>");
					   $("#tableInsertUpdate tr:eq(0)").after($idShow);
				   }
				   $("#submitForm").form('clear');
				   document.getElementById("id").value=row.id;
				   document.getElementById("com").value=row.com;
				   var ch = new Array();
				   ch = row.line.split("--");
				   document.getElementById("departure").value=ch[0];
				   document.getElementById("destination").value=ch[1];
				   document.getElementById("flight").value=row.flight;
				   $("#date").datebox("setValue",row.riqi);
				   document.getElementById("ahead").value=row.ahead;
				   $("#cabin").combobox("setValue",row.cabin);
				   document.getElementById("price").value=row.price;
				   document.getElementById("rate").value=row.rate.substring(0,row.rate.length-1);
			   }else{
				   var $secondTr = $("#tableInsertUpdate tr:eq(1)");
				   if($secondTr.attr("id")=='idtr'){
					   $secondTr.remove();
				   }
				   $("#submitForm").form('clear');
			   }
			   $('#opinionWindows').window('open');
			   $('#opinionWindows').panel('setTitle','添加/修改分舱位价格水平信息');
		       $('#submitForm').show();
		}
	 
		function remove(){
			var selectedRows = $('#opinionList').datagrid('getSelections');
			var removeIds = '';
			if (selectedRows.length>0){
				for(var i=0; i<selectedRows.length; i++){
					if (removeIds != '') removeIds += ',';
					removeIds += selectedRows[i].id;
				}
				$.messager.confirm('提示信息', '<div style="padding-top:15px;padding-left:5px"><b>确定删除？</b></div>', function(r){
					if (r){
						var url="priceAction!toRemovePrice.action";
						$.post(
								url,
								{"removeIds":removeIds},
								function(data){
									eval('data='+data);
						        	var state = data.state;
						        	var retMsg = data.resultMsg;
						        	if(state==true){
						        		$('#opinionList').datagrid("reload");
						        	}
						        	$.messager.alert('提示信息','<div style="padding-top:15px;padding-left:5px"><b>'+retMsg+'</b></div>','info');
								}
						);
					}
				});

			}else{
		    	$.messager.alert('提示信息','<div style="padding-top:15px;padding-left:5px"><b>请至少选择一条数据！</b></div>','warning');
		    }
		}
		
		function update(){
			var selectedRows = $('#opinionList').datagrid('getSelections');
			if (selectedRows.length>1){
				$.messager.alert('提示信息','<div style="padding-top:15px;padding-left:5px"><b>一次只能更新一条记录！</b></div>','warning');
			}
			else if (selectedRows.length==0){
		    	$.messager.alert('提示信息','<div style="padding-top:15px;padding-left:5px"><b>请选择其中一条数据进行更新！</b></div>','warning');
		    }
			else if (selectedRows.length==1){
				var row = selectedRows[0];
				$("#opinionWindows").height(330);
				WinOpen(row);
			}
		}
	  
		function save(){
			//添加和修改保存
			$("#line").val($("#departure").val() + "--" + $("#destination").val());
			$("#cabin").val($('#cabin').combobox('getText'));
			$("#rate").val($('#rate').val() + "%");
			$('#submitForm').form('submit',{
		        onSubmit: function(){
		        	return $('#submitForm').form('validate');
		        },
		        success:function(data){
		        	eval('data='+data);
		        	var state = data.state;
		        	var retMsg = data.resultMsg;
		        	$.messager.alert('提示信息','<div style="padding-top:15px;padding-left:5px"><b>'+retMsg+'</b></div>','info');
		        	if(state==true){
		    			$('#opinionList').datagrid('reload');
						$('#opinionWindows').window('close');
		        	}
		        }
			});
		}
	</script>
</head>
<body class="easyui-layout">
  
  <div id="opinionWindows" class="easyui-window" closed="true"
		iconCls="icon-save" draggable="false" modal="true" resizable="false"
		maximizable="false" minimizable="false" title="发表意见"
		style="width: 500px; height: 290px; padding: 2px; background: #fafafa;">
		<div id="priceForm" region="center" border="false"
			style="padding: 2px; background: #fff; border: 1px solid #ccc;">
			<%@include file="priceInsert.jsp"%>
		</div>
		<div region="south" border="false"
			style="text-align: right; height: 30px; line-height: 30px;">
			<a class="easyui-linkbutton" icon="icon-save"
				href="javascript:void(0)" onclick="save()">保存</a>
		    <a
				class="easyui-linkbutton" icon="icon-back"
				href="javascript:void(0);"
				onclick="javascript:$('#opinionWindows').window('close');">返回</a>
		</div>
	</div>
	
	
	
	<div region="center" title="增删查改操作" style="padding: 5px;" border="false">
		<table id="opinionList" fit="true" url="priceAction!getPriceListJSON.action">
			<thead>
				<tr>
				    <th field="com" width="130">公司</th>
				    <th field="line" width="130">航线</th>
					<th field="flight" width="130">航班</th>
					<th field="ahead" width="130">提前天数</th>
					<th field="cabin" width="130">舱位级别</th>
					<th field="price" width="130">价格</th>
					<th field="rate" width="130">客座率</th>
					<th field="riqi" width="130">日期</th>
					<th field="id" width="130">编号</th>
				</tr>
			</thead>
		</table>
	</div>
	
</body>
</html>